<template>
	<om-formsub-outer :index="index" :checkedit="checkedit" :deleteBtn="false">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				InstCacheKey:"hr-gw-tposGradeAdjust-posCareercatInfo-inst-cache",
				exists:"",
				postCacheKey:"hr-gw-tposGradeAdjust-posCareercatInfo-post-cache"
			})
		},
		methods:{
			onSelectAdjustPosGrade(item){
				this.getSalaryGradeRange(item.id)
			},
			getSalaryGradeRange(id){
				let _that = this
				_that.om.request(
					"salaryStandard/getSalaryGradeRange",
					{
						gradeId:id
					}
				).then(res=>{
					_that.$refs.autoform.formdata.gradeSalaryRange = res.value.str
				})
			},
			getDatas(id){
				let _that = this
				_that.om.request(
					"tposGradeAdjust/getDatas",
					{
						posId:id
					}
				).then(res=>{
					_that.$refs.autoform.formdata.salary = res.value.salary
					_that.$refs.autoform.formdata.testGrade = res.value.testGrade
					_that.$refs.autoform.formdata.origPosGrade = res.value.origPosGrade
				})
			},
			getGrade(id){
				let _that = this
				_that.om.request(
					"tposGradeAdjust/getGrade",
					{
						posId:id
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor("posCareercatInfo","adjustPosGradeId","data",configSelectData(res,"id","dicname"))
					_that.$refs.autoform.initSelectIndex("posCareercatInfo","adjustPosGradeId")
				})
			},
			
			verifyPos(){
				let _that = this
				if(_that.$refs.autoform.formdata.instId){
					return true
				}else{
					_that.om.toast("请先选择机构名称",3000)
					return false
				}
				
			},
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.InstCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							 formdata.instId = d.id
							 formdata.instName = d.instName
							 _that.autoformdata[0].editors[1].type = "linkbox"
							 _that.autoformdata[0].editors[1].verifyfunc = "verifyPos"
							 _that.autoformdata[0].editors[1].prompt = "请选择"
							 _that.autoformdata[0].editors[1].link = "../../public/pageSearch/pageSearch",
							 
							 _that.autoformdata[0].editors[1].linkParam = 
							 {
								 other: JSON.stringify({
										lList:_that.exists,
										instId:d.id
							 	}),
								namefield: "posname",
								url:"tposGradeAdjust/getPosList",
								method : "post",
								initload : true,
								cachename : _that.postCacheKey
							 }
							uni.removeStorage({
								key:_that.InstCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.postCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.posId = d.posid
							formdata.posName = d.posname
							_that.getDatas(d.posid)
							_that.getGrade(d.posid)
							uni.removeStorage({
								key:_that.postCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				_that.exists = _that.datas.filter((e,i)=>{
					return (i != _that.index)
				}).map(e=>e.instId).join(",")
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
								changeEditor("posCareercatInfo","instId",{
									"link":'/pages/public/pageSearch/pageSearch',
									"linkParam": {
										other: JSON.stringify({
											containBoard: true
										}),
										method: "post",
										namefield: 'instName',
										searchfield: "instName",
										initload: true,
										url: 'tinstitution/findNotBoard1',
										cachename: _that.InstCacheKey,
										placeholder: "请输入部门名称",
									}
								},null,_that.autoformdata)
							}
							_that.getGrade(_that.formdata.posId)
						}
					})
				}
							
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
